package deliciouse.servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import deliciouse.dao.NewsDao;
import deliciouse.dao.impl.NewsDaoImpl;
import deliciouse.entity.News;

@WebServlet ("/newslistmanegement")
public class NewsManegementServlet extends HttpServlet {

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String title = null;
		if(request.getParameter("title")!=null&& !request.getParameter("title").isEmpty())
			title=request.getParameter("title");
		NewsDao newsdao = new NewsDaoImpl();
		List<News> newslist = newsdao.getall();
		List<News> newslistcondition = newsdao.fetchByCondition(title);
		request.getSession().setAttribute("newslist", newslist);
		request.getSession().setAttribute("newslistcondition", newslistcondition);
		//request.setAttribute("newslist", newslist);
		//request.setAttribute("newslistcondition", newslistcondition);
		//request.getRequestDispatcher("/admin/newlistmanegement.jsp").forward(request, response);
		response.sendRedirect("admin/newlistmanegement.jsp");
	}

}
